/***********************************************************************************
  Filename:     flash,h

  Description:  This example uses a master to send data to a slave using SPI.

***********************************************************************************/

/***********************************************************************************
* INCLUDES
*/
#ifndef FLASH_H
#define FLASH_H
#include <hal_types.h>
#include <hal_defs.h>
#include <hal_cc8051.h>
#include <ioCCxx10_bitdef.h>
#include "string.h"
#include <ioCC2430.h>

#include  "FlashMemory.h"
/***********************************************************************************
* CONSTANTS
*/
#define START_STORAGE_BLOCK_NUM    0x01
#define MAX_BLOCK_NUM      4095
static uint8 FLASH_HEAD[4] = {0x20,0x09,0x09,0x09};
static uint8 COLLECT_TIME[2] = {0x00,0x01};
static uint8 LAST_SEND_POSITION[2] = {0x00,0x00};
static uint8 TEMP_THRESHOLD[2] = {0x00,0x28}; //0-40
static uint8 HUMI_THRESHOLD[2] = {0x00,0x46}; //0-70


//extern uint16 actual_write_block;

extern uint8  collect_minutes;
extern uint8  collect_seconds;
//extern uint16 last_send_block;
extern uint8  temp_threshold_L;
extern uint8  temp_threshold_H;
extern uint8  humi_threshold_L;
extern uint8  humi_threshold_H;

/***********************************************************************************
* LOCAL VARIABLES
*/

// Masters's transmit buffer
void delay(int time);
void *rev_memcpy(void *s1,  void *s2, size_t n);                  //[]to*
void *rev_memcpy1(void *s1,  void *s2, size_t n);                 //*to[]
void Flash_Initialize_App(void);
void RestoreFactorySet(void);
void LastSendBlockRead(void);
uint8 StoreLevel(void);
void Flash_write_App(uint8 *write_buf);
void Flash_read_App(uint16 page, uint8 *read_buf);
void CollectTimeWrite(uint8 collect_time_minutes,uint8 collect_time_seconds);
void ThresholdWrite(uint8 *threshold);
void LastSendBlockWrite(uint16 last_send_block);
void EraseChip(void);


#endif

